package com.ptswitch.material.pages.hlog;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.project.SplitPageInfo;

import com.ptswitch.material.model.common.HLog;
import com.ptswitch.material.pages.base.PageBase;
import com.ptswitch.material.service.HLogService;
import com.ptswitch.material.util.security.PermissionUtil;

public class ListHLog extends PageBase {

    @Inject
    private HLogService hlogSer;
    @Property
    private SplitPageInfo page = new SplitPageInfo();
    @Property
    private List<HLog> list;

    Object withInit() {
        return this;
    }

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(long size, long first) {
        checkPermitted(PermissionUtil.HlogList);
        page.setCurrentPage(first);
        page.setPageSize(size);
        return null;
    }

    @SetupRender
    Object display() {
        page.setRowCount(hlogSer.countAll());
        list = hlogSer.findAll(page.getCurrentRow(), page.getPageSize());
        return null;
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return new Object[] { page.getPageSize(), page.getCurrentPage() };
    }
}
